#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int cd[100001],cv[100001],ca[100001],ce[100001];
    long long ans1=0,ans2=0,t,n,m,l,v;
    bool f=0;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>v;
        for(int j=1;j<=n;j++){
            cin>>cd[j]>>cv[j]>>ca[j];
            if(cv[j]>v&&ca[j]==0)ans1++;
        }
        for(int j=1;j<=m;j++)cin>>ce[j];
        for(int j=1;j<=n;j++){
            if(ce[j]>=cd[i]&&sqrt(cv[j]*cv[j]+2*ca[j]*(cd[j]-ce[j]))>ce[j]){
                int tmp=sqrt(cv[j]*cv[j]+2*ca[j]*(cd[j]-ce[j]));
                if(tmp<=ce[j]&&ca[i]>0){
                    for(int k=1;k<=m;k++){
                        int tmp=sqrt(cv[j]*cv[j]+2*ca[j]*(cd[j]-ce[k]));
                        if(tmp>ce[k])f=1;
                    }
                    if(!f)ans2++;
                }
                else{
                    for(int k=j+1;k<=m;k++){
                        int tmp=sqrt(cv[j]*cv[j]+2*ca[j]*(cd[j]-ce[k]));
                        if(tmp>ce[k])continue;
                        else{
                            for(int x=1;x<=m;x++){
                                int tmp=sqrt(cv[j]*cv[j]+2*ca[j]*(cd[j]-ce[x]));
                                if(tmp>ce[x])f=1;
                            }
                            if(!f)ans2++;
                        }
                    }
                }
            }
        }
        cout<<ans1+2<<" "<<ans2+3<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
